import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:thinking/config/_.dart';
import 'package:thinking/utils/_.dart';

import 'PersonalTitleBottomWidget.dart';

class PersonalTitleBottom extends StatefulWidget {
  final int index;

  @override
  _PersonalTitleBottom createState() => _PersonalTitleBottom(index: index);

  PersonalTitleBottom({required this.index});
}

class _PersonalTitleBottom extends State<PersonalTitleBottom>
    with SingleTickerProviderStateMixin {
  late TabController _tabController;
  int index;
  List<String> titleList = ['think', '动态'];

  _PersonalTitleBottom({required this.index});

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: titleList.length, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  Widget title() {
    return Container(
      padding: EdgeInsets.only(top:Screen.setHeight(Config.top)),
      width: Screen.width(context),
      child: Align(
        alignment: Alignment.bottomCenter,
        child: TabBar(
          controller: _tabController,
          tabs: titleList.map((e) =>
              Padding(
                padding: EdgeInsets.only(top: 6,bottom: 10),
                child:Text(e) ,
              )
          ).toList(),
          isScrollable: true,
          labelColor: ColorConfig.ThemeColor,
          labelStyle:TextStyle(fontSize: 18,fontWeight: FontWeight.w600),
          unselectedLabelColor: ColorConfig.NoActiveColor,
          unselectedLabelStyle:TextStyle(fontSize: 16) ,
          indicatorColor: ColorConfig.ThemeColor,
          indicatorPadding: EdgeInsets.all(0),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(Screen.setHeight(50)),
        child: title(),
      ),
      body: Container(
        child: TabBarView(
            controller: _tabController,
            children: titleList
                .asMap()
                .keys
                .map((e) => PersonalTitleBottomWidget(pageIndex: e,reqIndex:index))
                .toList()),
      ),
    );
  }
}
